gl path "~/Dropbox/voter_id/Replication"

cap log close
log using "$path/figure1_and_a2.log", replace

use "$path/provisional_ballots.dta", clear

keep if general == 0
gen count = 1
collapse (sum) count, by(reason year)
egen total_by_year = sum(count), by(year)
gen rate = count / total_by_year
sort year reason
replace reason = "INCORRECT PRECINCT" if reason == "INCORRECT PRECINCT / UNREPORTED MOVE"

binscatter rate year, by(reason) linetype(connect) ///
	xtitle("") ytitle("Share of Provisional Ballots")  ///
	legend(position(6) rows(2) size(vsmall) order(1 2 3 5 4) ///
	lab(1 "ID NOT PROVIDED") lab(2 "INCORRECT PRECINCT") lab(3 "NOT REGISTERED") ///
	lab(5 "PREVIOUSLY REMOVED") lab(4 "OTHER")) ///
	xsize(5) ysize(5)
	
graph export "$path/figure_a2_left.pdf", replace

keep if reason == "ID NOT PROVIDED" | reason == "NOT REGISTERED"

binscatter rate year, by(reason) linetype(connect) ///
	xtitle("") ytitle("Share of Provisional Ballots") ///
	scale(1.3) text(0.65 2014 "Not Registered") ///
	text(0.1 2014 "ID Not Provided") legend(off) ///
	lcolor(black) mcolor(black)
	
graph export "$path/figure_1_left.pdf", replace


use "$path/provisional_ballots.dta", clear

keep if general == 1
gen count = 1
collapse (sum) count, by(reason year)
egen total_by_year = sum(count), by(year)
gen rate = count / total_by_year
sort year reason
replace reason = "INCORRECT PRECINCT" if reason == "INCORRECT PRECINCT / UNREPORTED MOVE"

binscatter rate year, by(reason) linetype(connect) ///
	xtitle("") ytitle("Share of Provisional Ballots")  ///
	legend(position(6) rows(2) size(vsmall) order(1 2 3 5 4) ///
	lab(1 "ID NOT PROVIDED") lab(2 "INCORRECT PRECINCT") lab(3 "NOT REGISTERED") ///
	lab(5 "PREVIOUSLY REMOVED") lab(4 "OTHER")) ///
	xsize(5) ysize(5)
	
graph export "$path/figure_a2_right.pdf", replace

keep if reason == "ID NOT PROVIDED" | reason == "NOT REGISTERED"

binscatter rate year, by(reason) linetype(connect) ///
	xtitle("") ytitle("Share of Provisional Ballots") ///
	scale(1.3) text(0.77 2013.7 "Not Registered") ///
	text(0.1 2014 "ID Not Provided") legend(off) ///
	lcolor(black) mcolor(black)
	
graph export "$path/figure_1_right.pdf", replace

log close
